package com.niit.serializtion;

import org.junit.Test;

import java.io.*;

public class addr {
    //实现序列化
    @Test
    public void ser() throws IOException{
        //将结构化对象，序列化为一个文件
        File file = new File("input/student.txt");
        //文件输入流
        FileOutputStream outputStream = new FileOutputStream(file);
        //数据输入流
        DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
        //创建结构化对象
        student student = new student(1120110,"tiancheng","nan",20,"bobai");
        student.write(dataOutputStream);
        dataOutputStream.close();
        outputStream.close();
        System.out.println("序列化成功！！");
    }

    //反序列化
    @Test
    public <student> void deSer() throws IOException{
        //将文件中的内容 反序列化 成 我的结构化对象
        File file = new File("input/student.txt");
        //文件输入流
        FileInputStream inputStream = new FileInputStream(file);
        //数据输入出流
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        //创建结构化对象
        //person person =new person();
        com.niit.serializtion.student student =new com.niit.serializtion.student();
        student.readFields(dataInputStream);
        dataInputStream.close();
        inputStream.close();
        System.out.println("反序列化成功："+student.toString());

    }
}
